package com.wenli.lt.service.impl;

import com.wenli.lt.entity.Classes;
import com.wenli.lt.entity.College;
import com.wenli.lt.mapper.ClassMapper;
import com.wenli.lt.mapper.CollegeMapper;
import com.wenli.lt.service.IClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lt
 * @since 2021-03-21
 */
@Service
public class ClassServiceImpl extends ServiceImpl<ClassMapper, Classes> implements IClassService {

    @Autowired
    ClassMapper classMapper;

    @Autowired
    CollegeMapper collegeMapper;

    @Override
    public boolean addClass(Classes classes) {
        classes.setClassId(UUID.randomUUID().toString().replace("-",""));
        College college = collegeMapper.selectById(classes.getCollegeId());
        classes.setGradeId(college.getGradeId());
        return 1 ==  classMapper.insert(classes);
    }
}
